# Class definitions for generic objects and reporting.
# Non reporting methods
###############################################################################


#' The "abstract" base class of all classes.
#' 
#' Object is needed to allow a  objects to refer to other objects of the same type. 
#' It implements a simple call by reference mechanism.
#' @author Bastian R. Angermann
#' @aliases Object-class
setClass(Class="Object",representation=representation("referenceContainer"="environment"))

# see below
setGeneric(name="setValue",
        def=function(object, slot, value) standardGeneric("setValue") )

#' Assigns a value to an environment that is part of an instance of an Object class.
#' 
#' This implements a reference mechanism in R by storing objects aggregated by an instance of
#' the Object-class in an environment. This allows to write code in a more readable less error prone way.
#' E.g. instead of writing object <- changeState(object) we simply use changeState(object)
#' without the need to explicitly assign the result of the state change back to the object. 
#' @param object The object in which a slot should be set.
#' @param slot The name of variable aggregated by the object
#' @param value The value that will be assigned to the slot named in the slot parameter.
#' @author Bastian R. Angermann
#' @aliases setValue setValue-methods setValue,Object,character,ANY-method setValue,Object,character-method
#' @export
setMethod("setValue", signature(object="Object", slot="character", value="ANY"), function (object, slot, value){
    assign(substitute(slot), value, envir=object@referenceContainer)
})


# see below
setGeneric(name="getValue",
        def=function(object, slot) standardGeneric("getValue") )

#' Read a value from an environment that is part of an instance of an Object class.
#' 
#' This implements a reference mechanism in R by storing objects aggregated by an instance of
#' the Object-class in an environment.  
#' @param object The object from which a slot should be read.
#' @param slot The name of variable aggregated by the object
#' @return value The value of the object in the slot named in the slot parameter.
#' @author Bastian R. Angermann
#' @aliases getValue getValue-methods getValue,Object,character-method
#' @export
setMethod("getValue", signature(object="Object", slot="character"), function (object, slot){
    tryCatch(get(slot, envir=object@referenceContainer),             
        error=function(x) {return(NULL)})                    
})


#' Handles submission of reports to a connection.
#' 
#' Reporting can be done in different ways, e.g. by writing directly to disk or submitting entries to a data base.
#' This class encodes the way reporting is done and separates the configuration of reporting from reporting itself.
#' @author Bastian R. Angermann
#' @aliases report-class
setClass(Class="Report",
        representation=representation("location"="function","master"="logical"),contains="Object")

#' Handles the generation of html reports.
#' 
#' Generates reports in Html format.
#' @author Bastian R. Angermann
#' @aliases HtmlReport-class
#' @export 
setClass(Class="HtmlReport", contains="Report")


